home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / pbm / pbmtoeps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-06  |  2.1 KB  |  82 lines

  1. /* pbmtoeps.c - read a portable bitmap and produce Epson graphics
  2. **
  3. ** Copyright (C) 1990 by John Tiller (tiller@galois.msfc.nasa.gov)
  4. **             and Jef Poskanzer.
  5. **
  6. ** Permission to use, copy, modify, and distribute this software and its
  7. ** documentation for any purpose and without fee is hereby granted, provided
  8. ** that the above copyright notice appear in all copies and that both that
  9. ** copyright notice and this permission notice appear in supporting
  10. ** documentation.  This software is provided "as is" without express or
  11. ** implied warranty.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include "pbm.h"
  16.  
  17. static int mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  18.  
  19. void
  20. main( argc, argv )
  21.     int argc;
  22.     char* argv[];
  23.     {
  24.     FILE* ifp;
  25.     bit** bits;
  26.     bit* bP[8];
  27.     int rows, cols, row, col, lastcol;
  28.     int idx;
  29.     int val;
  30.  
  31.     pbm_init( &argc, argv );
  32.  
  33.     if ( argc > 2 )
  34.     pm_usage( "[pbmfile]" );
  35.  
  36.     if ( argc == 2 )
  37.     ifp = pm_openr( argv[1] );
  38.     else
  39.     ifp = stdin;
  40.  
  41.     bits = pbm_readpbm( ifp, &cols, &rows );
  42.  
  43.     pm_close( ifp );
  44.     
  45.     /* Change line spacing to 8/72 inches. */
  46.     fprintf (stdout, "\033A\010");
  47.     /* Write out rows by eights. */
  48.     for ( row = 0; row < rows; row += 8 )
  49.     {
  50.     /* Find end of lines. */
  51.     for ( lastcol = cols-1; lastcol >= 0; --lastcol )
  52.         {
  53.         for ( idx = 0; idx < 8 && row+idx < rows; ++idx )
  54.         if ( bits[row+idx][lastcol] == PBM_BLACK )
  55.             break;
  56.         if ( idx < 8 && row+idx < rows )
  57.         break;
  58.         }
  59.     for ( idx = 0; idx < 8 && row+idx < rows; ++idx )
  60.         bP[idx] = bits[row+idx];
  61.     /* Put in plotter (1:1) graphics. */
  62.     if ( lastcol >= 0 )
  63.         fprintf (stdout, "\033*\005%c%c", (lastcol+1)%256, (lastcol+1)/256);
  64.         for ( col = 0; col <= lastcol; ++col )
  65.         {
  66.         val = 0;
  67.         for ( idx = 0; idx < 8 && row+idx < rows; ++idx )
  68.         if ( *bP[idx] == PBM_BLACK )
  69.             val |= mask[idx];
  70.         putchar( val );
  71.         for ( idx = 0; idx < 8 && row+idx < rows; ++idx )
  72.         ++bP[idx];
  73.         }
  74.     putchar( '\n' );
  75.         }
  76.     putchar( '\f' );
  77.     /* Restore normal line spacing. */
  78.     fprintf (stdout, "\033@");
  79.     pm_close (stdout);
  80.     exit( 0 );
  81.     }
  82.